use std::ops::Add;

//为Point结构体派生Debug特征,用于格式输出
#[derive(Debug)]
struct Point<T: Add<T, Output=T>> { // 限制类型T必须实现Add特征,否则无法进行+操作
    x: T,
    y: T,

}

impl<T: Add<T, Output=T>> Add for Point<T> {
    type Output = Point<T>;
    fn add(self, p: Point<T>) -> Point<T> {
        Self {
            x: self.x + p.x,
            y: self.y + p.y,
        }
    } 
}

fn add<T: Add<T, Output=T>>(a: T, b: T) -> T {
    a + b 
}

fn main() {
    let p1 = Point{x: 1.1f32, y: 2.1f32};
    let p2 = Point{x: 2.0f32, y: 3.0};
    println!("{:?}", add(p1, p2));

}
